package avriServer.channel.chat;

import java.util.LinkedList;

import avriServer.channel.Channel;
import avriServer.channel.NonexistantChannelException;
import avriServer.channel.WrongChannelNameException;
import avriServer.client.Waiter;

public class ChatChannel extends avriServer.channel.Channel{
	
	public ChatChannel(String _channelNameOrAbsoluteName) throws WrongChannelNameException {
		super(_channelNameOrAbsoluteName);
	}
	/**
	 * Save a message _message in the channel _channel
	 * @param _channel
	 * @param _message
	 * @throws NonexistantChannelException 
	 *//*
	public void saveMessage (String _channel, String _message ) throws NonexistantChannelException {
		if (this.listChannel.containsKey(_channel))
			this.listChannel.get(_channel).save(_message);
		else
			throw new NonexistantChannelException();

	}
	
	public String getSavedMessage (String _channel) throws NonexistantChannelException{
		Channel<User, Waiter> c = this.listChannel.get(_channel) ;
		if (c == null)
			throw new NonexistantChannelException();
		LinkedList<String> ls = c.getSavedMessage() ;
		
		StringBuffer sb = new StringBuffer("Last Messages :") ;
		for (String s : ls) {
			sb.append("<br />"+s);
		}
		return sb.toString() ;
	}
	/**
	 * Add a channel on the dispatcher's list
	 * @param _nameChannel
	 *//*
	public synchronized void addChannel(String _nameChannel) {
		//this.listChannel.put(_nameChannel, (Map<String, Waiter>) Collections.synchronizedMap(new HashMap<String, Waiter>()));
		if(!this.listChannel.containsKey(_nameChannel))
			this.listChannel.put(_nameChannel, (Channel<User, Waiter>) new Channel<User, Waiter>());
	}
	private LinkedList<String> message = new LinkedList<String>();
	/**
	 * Save a message in the list of the message of this channel.
	 * @param _message
	 *//*
	public void save (String _message) {
		this.timeLastMessage = System.currentTimeMillis() ;
		this.message.add(_message);
		if(this.message.size()>Server.NUMBER_MESSAGE_SAVED)
			this.message.remove(0);
	}
	public boolean isKeptAlive () {
		return (System.currentTimeMillis() - this.timeLastMessage < Server.KEEPALIVE_CHANNEL);
	}
	public LinkedList<String> getSavedMessage () {
		return this.message ;
	}*/

}
